//
//  MusicChorusTableViewCell.m
//  CCBbelefitLife
//
//  Created by 小晓 on 16/1/10.
//  Copyright © 2016年 liurg. All rights reserved.
//

#import "MusicChorusTableViewCell.h"
#import "KSingingRecordViewCtr.h"

@interface MusicChorusTableViewCell()

{
    UIImageView * headImageView;
    UIViewController *_currentViewCtr;
    UILabel * userNameLabel;
    UILabel * peopleCountLabel;
    UILabel * titleLabel;
    UILabel * musicLabel;
    NSString* _musicUrl;
    NSString* _lyrUrl;
}

@end

@implementation MusicChorusTableViewCell

- ( instancetype ) initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        UIView * headerLineView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, mainScreenWidth, 5)];
        headerLineView.backgroundColor = JYColor(242, 242, 242);
        [self.contentView addSubview:headerLineView];
        
        headImageView = [[UIImageView alloc]initWithFrame:CGRectMake(15, 15, 60, 60)];
        [self.contentView addSubview:headImageView];
        
        userNameLabel = [[UILabel alloc]initWithFrame:CGRectMake(85, 15, mainScreenWidth-85-40, 20)];
        userNameLabel.textColor = JYColor(227, 110, 37);
        [self.contentView addSubview:userNameLabel];
        
        musicLabel = [[UILabel alloc]initWithFrame:CGRectMake(85, 40, mainScreenWidth-85-40, 12)];
        musicLabel.font = [UIFont systemFontOfSize:14];
        [self.contentView addSubview:musicLabel];
        
        peopleCountLabel = [[UILabel alloc]initWithFrame:CGRectMake(85, 57, mainScreenWidth-85-40, 10)];
        peopleCountLabel.textColor = [UIColor blackColor];
        peopleCountLabel.font = [UIFont systemFontOfSize:14];
        [self.contentView addSubview:peopleCountLabel];
        
        titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(85, 72, mainScreenWidth-95, 20)];
        titleLabel.numberOfLines = 0;
        titleLabel.font = [UIFont systemFontOfSize:12];
        titleLabel.backgroundColor = JYColor(242, 242, 242);
        [self.contentView addSubview:titleLabel];
        
        UIButton * rightBtn = [[UIButton alloc]initWithFrame:CGRectMake(mainScreenWidth-35, 15, 30, 30)];
        [rightBtn setImage:[UIImage imageNamed:@"图层-12-拷贝-3@2x.png"] forState:(UIControlStateNormal)];
        [rightBtn addTarget:self action:@selector(KmusicView:) forControlEvents:(UIControlEventTouchUpInside)];
        [self.contentView addSubview:rightBtn];
        
    }
    return self;
}

- (void)updataCellViewWithHeadData:(KMusicMsgDataModel * )musicModel superViewCtr:(UIViewController *)superVierCtr{
    [headImageView sd_setImageWithURL:[NSURL URLWithString:musicModel.avatar] placeholderImage:[UIImage imageNamed:@"图层-27@2x.png"]];
    userNameLabel.text = musicModel.name;
    musicLabel.text = musicModel.nickName;
    _musicUrl = musicModel.accompanyUrl;
    _lyrUrl = musicModel.lyric;
    _currentViewCtr = superVierCtr;
    if(!musicModel.isSolo){
        peopleCountLabel.text = [NSString stringWithFormat:@"%@人合唱过",musicModel.chorusNum];
    }else{
        peopleCountLabel.frame = CGRectZero;
    }
    NSString * title = musicModel.musicDes;
    if(!title){
        titleLabel.hidden = YES;
    }else{
        titleLabel.hidden = NO;
        titleLabel.text = title;
        UIFont *font = [UIFont systemFontOfSize:13];
        CGSize size = CGSizeMake(mainScreenWidth-95,2000);
        CGSize labelsize = [titleLabel.text sizeWithFont:font constrainedToSize:size lineBreakMode:UILineBreakModeWordWrap];
        if(!musicModel.isSolo){
           [titleLabel setFrame:CGRectMake(85, 72, labelsize.width, labelsize.height)];
        }else{
            [titleLabel setFrame:CGRectMake(85, 57, labelsize.width, labelsize.height)];
        }
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

-(void)KmusicView:(UIButton *)seader{
    KSingingRecordViewCtr * kSingViewCtr = [KSingingRecordViewCtr new];
    kSingViewCtr.musicUrl = _musicUrl;
    kSingViewCtr.lyrUrl = _lyrUrl;
    kSingViewCtr.singerName = musicLabel.text;
    kSingViewCtr.musicName = userNameLabel.text;
    [_currentViewCtr.navigationController pushViewController:kSingViewCtr animated:YES];
}

@end
